#include <iostream>
#include <sstream>
#include <string>
#include <queue>
using namespace std;

struct Node {
	string val;
	Node* left = nullptr;
	Node* right = nullptr;
};
string sp;
Node* A = nullptr;
int c = 0;
void getTree(Node*& h)
{
	h = new Node;
	queue<Node*> q;
	string line;
	getline(cin, line);
	stringstream ss(line);
	ss >> h->val;
	q.push(h);
	while (q.size()) {
		Node* cur = q.front(); q.pop();
		string l, r;
		if (!(ss >> l))break;
		if (l != sp) {
			cur->left = new Node;
			cur->left->val = l;
			q.push(cur->left);
		}
		if (!(ss >> r))break;
		if (r != sp) {
			cur->right = new Node;
			cur->right->val = r;
			q.push(cur->right);
		}
	}
}

int getL(Node* h, int jug) // -1 left 0 root 1 right
{
	if (!h) return 0;
	if (h->left || h->right) {
		int l = getL(h->left, -1);
		int r = getL(h->right, 1);
		return l + r;
	}
	else {
		if (jug == -1) return stoi(h->val);
		else return 0;
	}
}

int main()
{
	getline(cin, sp);
	sp = "null";
	getTree(A);

	cout << getL(A, 0);

	return 0;
}